//
//  RootViewController.m
//  Baymax
//
//  Created by jolin on 16/4/18.
//  Copyright © 2016年 jolin. All rights reserved.
//

#import "RootViewController.h"
#import "FeelingViewController.h"
#import "Header.h"
#import "SuperID.h"

#define ButtonWidth 80
#define Spacing 80

@interface RootViewController ()<SuperIDDelegate> {
    SuperID *_superIdSdk;
}

@end

@implementation RootViewController

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    _superIdSdk = [SuperID sharedInstance];
    _superIdSdk.delegate = self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor yellowColor];
    
    //self.title = @"心情";
    [self initView];
}
#pragma mark - 初始化视图
- (void)initView {
    NSArray *btnTitles = @[@"拍照", @"语音", @"心率", @"选择"];
    //拍照测心情
    for (int i = 0; i < 4; i++) {
        UIButton *testBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        testBtn.frame = CGRectMake(70 + (Spacing+ButtonWidth) * (i%2), 150 + (Spacing+ButtonWidth) * (i/2), ButtonWidth, ButtonWidth);
        testBtn.tag = 10 + i;
        testBtn.backgroundColor = [UIColor orangeColor];
        testBtn.layer.cornerRadius = 5;
        [testBtn setTitle:btnTitles[i] forState:UIControlStateNormal];
        [testBtn addTarget:self action:@selector(testFeeling:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:testBtn];
    }
    
}

#pragma mark - 测试心情
- (void)testFeeling:(UIButton *)sender {
    
    switch (sender.tag - 10) {
        case 0:{
            NSError *error = nil;
            id SIDEmotionViewController = [[SuperID sharedInstance] obtainFaceFeatureViewControllerWithError:&error];

            if (SIDEmotionViewController) {
                [self presentViewController:SIDEmotionViewController animated:YES completion:nil];
            }else {
                NSLog(@"loginView Error =%ld,%@",(long)[error code],[error localizedDescription]);
            }
            
        }break;
        case 1:
            
            break;
        case 2:
            
            break;
        case 3:
            
            break;
        default:
            break;
    }
}

#pragma mark - 拍照返回信息回调方法
- (void)superID:(SuperID *)sender userDidFinishGetFaceFeatureWithFeatureInfo:(NSDictionary *) featureInfo error:(NSError *)error {
    //NSLog(@"面部信息:%@",featureInfo);
    //如果没有错误 跳转到心情页面
    if (!error) {
        FeelingViewController *feelingVC = [[FeelingViewController alloc]init];
        feelingVC.featureInfo = featureInfo;
        //将信息传到心情页面
        [self.navigationController pushViewController:feelingVC animated:NO];

    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
